package com.soft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Banji;
import com.soft.entity.Dept;
import com.soft.entity.Emp;
import com.soft.entity.Xuesheng;
import com.soft.mapper.BanjiMapper;
import com.soft.mapper.XueshengMapper;

@Service
public class XueshengService {
	@Autowired
	private BanjiMapper banjiMapper;
	@Autowired
	private XueshengMapper xueshengMapper;
	public List<Xuesheng> queryByBanjiName(String banjiTeacher) {
	    QueryWrapper<Banji> banjiWrapper = new QueryWrapper<>();
	    banjiWrapper.eq("banji_teacher", banjiTeacher);
	    Banji banji = banjiMapper.selectOne(banjiWrapper);

	    QueryWrapper<Xuesheng> xueshengWrapper = new QueryWrapper<>();
	    xueshengWrapper.eq("banji_banjihao", banji.getBanjiBanjihao());
	    List<Xuesheng> xueshengList = xueshengMapper.selectList(xueshengWrapper);

	    return xueshengList;
	}
	 public int insertXuesheng(String name, String loc,String banjiTeacher) {
	        QueryWrapper<Banji> banjiWrapper = new QueryWrapper<>();
	        banjiWrapper.eq("banji_teacher", banjiTeacher);
	        Banji banji = banjiMapper.selectOne(banjiWrapper);

	        Xuesheng xuesheng = new Xuesheng();
	        xuesheng.setXueshengName(name);
	        xuesheng.setXueshengLoc(loc);
	        xuesheng.setBanjiBanjihao(banji.getBanjiBanjihao());
	        int num = xueshengMapper.insert(xuesheng);
	        return num;
	    }
	 public int updateXuesheng(String name, String loc, String teacher) {
		    QueryWrapper<Banji> banjiWrapper = new QueryWrapper<>();
		    banjiWrapper.eq("banji_teacher", teacher);
		    Banji banji = banjiMapper.selectOne(banjiWrapper);

		    QueryWrapper<Xuesheng> xueshengWrapper = new QueryWrapper<>();
		    xueshengWrapper.eq("banji_banjihao", banji.getBanjiBanjihao());
		    xueshengWrapper.eq("xuesheng_name",name);
		    Xuesheng xuesheng = xueshengMapper.selectOne(xueshengWrapper);
		    xuesheng.setXueshengLoc(loc);
		    int num = xueshengMapper.updateById(xuesheng);
		    return num;
		}

}
